var pictureSource;   // picture source
var destinationType; // sets the format of returned value 

// PhoneGap is ready to be used!
function onDeviceReady() {
	alert('onDeviceReady');
    pictureSource=navigator.camera.PictureSourceType;
    destinationType=navigator.camera.DestinationType;
}

// Called when a photo is successfully retrieved
function onPhotoDataSuccess(imageData) {
    var photo = document.getElementById('photo');
    photo.src = "data:image/jpeg;base64," + imageData;
}

// Called when a photo is successfully retrieved
function onPhotoURISuccess(imageURI) {
    var photo = document.getElementById('photo');
    photo.background = imageURI;
}

function capturePhoto() {
      // Take picture using device camera and retrieve image as base64-encoded string
    navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50 });
}

function capturePhotoEdit() {
    // Take picture using device camera, allow edit, and retrieve image as base64-encoded string  
    navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 20, allowEdit: true }); 
}

function getPhoto(source) {
	alert('get photo');
    // Retrieve image file location from specified source
    navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50, 
    destinationType: destinationType.FILE_URI,
    sourceType: source });
}

// Called if something bad happens.
function onFail(message) {
    // alert('Failed because: ' + message);
}


var scrollableframe;
function loaded() {
    // scrollableframe = new iScroll('scrollableframe',
    //                       { useTransition:false,
    //                         checkDOMChanges: true,
    //                         hideScrollbar: true,
    //                         fixedScrollbar:true,
    //                         bounceLock: true,
    //                         onBeforeScrollStart: function (e) {
    //                             var target = e.target;
    //                             while (target.nodeType != 1) target = target.parentNode;

    //                             if (target.tagName != 'SELECT' && target.tagName != 'OPTION' && target.tagName != 'INPUT' && target.tagName != 'TEXTAREA' && target.tagName != 'BUTTON')
    //                                 e.preventDefault();
    //                         } }
    //                     );

    // $('.button')
    //     .on('touchstart', function () {
    //         $(this).addClass('fake-active');
    //     })
    //     .on('touchend', function() {
    //         $(this).removeClass('fake-active');
    //     })
    //     .on('touchcancel', function() {
    //         $(this).removeClass('fake-active');
    //     });

    // var allSelects = $('button');
    // allSelects.each(function(index, item) {
    //                   item.addEventListener('touchstart', function(e) { /*e.stopPropagation();*/ $(this).addClass("fake-active"); }, false);
    //                   item.addEventListener('touchend', function(e) { $(this).removeClass("fake-active"); }, false);
    //                   item.addEventListener('touchcancel', function(e) { $(this).removeClass("fake-active"); }, false);
    //                 });
}

document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
// document.addEventListener('DOMContentLoaded', loaded, false);
loaded();
// Wait for PhoneGap to connect with the device
//document.addEventListener("deviceready",onDeviceReady,false);
